package com.example.untitled1

import android.os.Build
import androidx.annotation.RequiresApi
import io.flutter.plugin.common.BasicMessageChannel
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.StandardMessageCodec

class BasicMessageChannelDemo(messenger: BinaryMessenger, private val bleManager: BleManager) :BasicMessageChannel.MessageHandler<Any?>{

    private val channel:BasicMessageChannel<Any?>

    init {
        channel = BasicMessageChannel(messenger, "com.example.ble_test.BasicMessageChannel", StandardMessageCodec.INSTANCE)
        channel.setMessageHandler(this)
    }

    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    override fun onMessage(message: Any?, reply: BasicMessageChannel.Reply<Any?>) {
        val bytes = message as ByteArray
        bleManager.separate(bytes)
    }

}
